<template>
  <div class="todo-footer">
    <label>
      <input type="checkbox" :checked='total === fineshtodo' @input="handleIsAll" />
    </label>
    <span>
      <span>已完成{{ fineshtodo }}</span> / 全部{{ total }}
    </span>
    <button class="btn btn-danger" @click="handleClean">清除已完成任务</button>
  </div>
</template>

<script>
export default {
  name: 'TodoFooter',
  props: ['todos', 'cleanchecktodo', 'checkAlltodo'],
  computed: {
    total() {
      // 计算总数
      return this.todos.length
    },
    // 计算已完成的(返回一个新的数组 里面的数据都是已经完成的)
    fineshtodo() {
      return this.todos.filter((item) => item.done).length
    },
    // 计算全选

  },
  methods: {
    handleClean() {
      if (confirm('确定要删除已经完成的任务吗 ?')) {
        this.cleanchecktodo();
      }
    },
    // 全选的回调
    handleIsAll(e) {
      this.checkAlltodo(e.target.checked)
      // console.log(e.target.checked);
    }
  },
}
</script>

<style scoped>
/*footer*/
.todo-footer {
  height: 40px;
  line-height: 40px;
  padding-left: 6px;
  margin-top: 5px;
}

.todo-footer label {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}

.todo-footer label input {
  position: relative;
  top: -1px;
  vertical-align: middle;
  margin-right: 5px;
}

.todo-footer button {
  float: right;
  margin-top: 5px;
}
</style>